﻿#coding=utf-8
from django import forms

class ItemForm(forms.Form):
	idx = forms.IntegerField(required=False)
	itemid = forms.IntegerField(required=False)
	itemname = forms.CharField(label='商品名称',error_messages={'required': '填写商品名称'})
	price = forms.IntegerField(label='单价',required=False)
	num = forms.IntegerField(label='数量',error_messages={'required': '填写数量'})
	priceall = forms.IntegerField(label='总价',required=False)
	satisfaction = forms.ChoiceField(choices=((5,5),(4,4),(3,3),(2,2),(1,1)),label='满意度')
	brand = forms.CharField(label='品牌',help_text='请输入商品的牌子',required=False)
	market = forms.CharField(label='商场',help_text='请输入购买的商场名称',required=False)
	otherinfo = forms.CharField(widget=forms.Textarea(),label='其他信息',required=False)
	
	def clean(self):
		price = self.cleaned_data['price']
		priceall=self.cleaned_data['priceall']
		if price==None and priceall==None:
			self._errors["price"] = self.error_class(['单价和总价不能全为空'])
			self._errors["priceall"] = self.error_class(['单价和总价不能全为空'])
		return self.cleaned_data

